#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void swap(int* x, int* y) {
    int c = *x;
    *x = *y;
    *y = c;
}
void Quicksort(int* a, int left, int end) {
    if (left >= end)
        return;
    int x = left, y = end;
    int front = left, behind = left + 1;
    int keyi = left;
    while (behind <= end) {
        if (a[behind] < a[keyi] && ++front != behind) {
            swap(&a[behind], &a[front]);
        }
        behind++;
    }
    swap(&a[keyi], &a[front]);
    Quicksort(a, left, front - 1);
    Quicksort(a, front + 1, end);
}
int maximumBags(int* capacity, int capacitySize, int* rocks, int rocksSize, int additionalRocks) {
    int x = 0, y = additionalRocks;
    int k = capacitySize > rocksSize ? capacitySize : rocksSize;
    int* a = (int*)malloc(k * sizeof(int));
    for (int i = 0; i < k; i++) {
        a[i] = abs(capacity[i] - rocks[i]);
        if (a[i] == 0)
            x++;
    }
    Quicksort(a, 0, k - 1);
    for (int i = 0; i < k; i++) {
        if (a[i] != 0&& y - a[i] >= 0) {
            x++;
            y -= a[i];
        }
    }
    return x;
}
int main() {
    int a[] = { 2,3,4,5 };
    int b[] = { 1,2,4,4 };
    printf("%d", maximumBags(a, 4, b, 4, 2));
}